<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" type="text/css" href="../static/plugins/jquery-easyui-1.10.19/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="../static/plugins/jquery-easyui-1.10.19/themes/icon.css">
    <script type="text/javascript" src="../static/plugins/jquery-easyui-1.10.19/jquery.min.js"></script>
    <script type="text/javascript" src="../static/plugins/jquery-easyui-1.10.19/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="../static/plugins/jquery-easyui-1.10.19/datagrid-export.js"></script>
    <script type="text/javascript" src="../static/plugins/jquery-easyui-1.10.19/locale/easyui-lang-zh_CN.js"></script>

    <script>
        $(function () {
            let value = '<%=session.getAttribute("username")%>';
            console.log(value)
            $('#dg').datagrid({
                url: '/lab00/StudentServlet?action=getdglist',
                toolbar: '#tb',
                method: 'post',
                queryParams: {
                    key1: value,
                },
                pagination: true,
                fit: true,
                singleSelect: true,//分页
                columns: [[
                    {field: 'sno', title: '学号', width: 100},
                    {field: 'sname', title: '姓名', width: 100},
                    {field: 'cno', title: '课程号', width: 100},
                    {field: 'cname', title: '课程名', width: 100},
                    {field: 'teacher', title: '教师', width: 100},
                    {field: 'semester', title: '学期', width: 100},
                    {field: 'grades', title: '成绩', width: 100}
                ]]
            });

            // $('#dg').datagrid({
            //     url: '/lab00/ServletAchievement?action=search',
            //     method: 'post',
            //     queryParams: {
            //         key1: value,
            //     },
            //     toolbar: '#tb',
            //     fit: true,
            //     columns: [[
            //         {field: 'sno', title: '学号', width: 100},
            //         {field: 'sname', title: '姓名', width: 100},
            //         {field: 'cno', title: '课程号', width: 100},
            //         {field: 'cname', title: '课程名', width: 100},
            //         {field: 'teacher', title: '教师', width: 100},
            //         {field: 'semester', title: '学期', width: 100},
            //         {field: 'grades', title: '成绩', width: 100}
            //     ]],
            //     onLoadSuccess: function(data){ // 数据加载成功后的回调函数
            //         console.log("Data loaded successfully.");
            //     }
            // });



            //导出功能
            $('#btnexport').click(function (){
                $('#dg').datagrid("toExcel", "成绩信息.xls");
            })

        })
    </script>

</head>
<body class="easyui-layout">
<div data-options="region:'center',border:false">
    <table id="dg"></table>
</div>
<div id="dd"></div>
<div id="tb" style="height:auto">
    <table>
        <tr>
<%--            <td><a id="btnAdd" href="javascript:void(0)" class="easyui-linkbutton"--%>
<%--                   data-options="iconCls:'icon-add',plain:true">添加</a></td>--%>
             <td>
                 <div class="datagrid-btn-separator"></div>
            </td>
            <td><a id="btnexport" href="javascript:void(0)" class="easyui-linkbutton"
                   data-options="iconCls:'icon-save',plain:true">导出</a>
            </td>
            <td>
                <input id="btnSearch" class="easyui-searchbox" data-options="prompt:'请输入课程号',searcher:doSearch">
            </td>
            <script>
                function doSearch(value){

                    console.log("1111")
                    if (value == ""){
                        $.messager.alert('提示', '请选择要搜索的数据', 'warning');
                    }else {
                        $.ajax({
                            type:"POST",
                            url:"/lab00/StudentServlet?action=search",
                            data:{key1:value},
                            success:function (ret)
                            {
                                debugger
                                let result = eval("(" +ret+")");
                                if(result !="404")
                                    $('#dg').datagrid({
                                        url: '/lab00/StudentServlet?action=search',
                                        method: 'post',
                                        queryParams: {
                                            key1: value,
                                        },
                                        toolbar: '#tb',
                                        fit: true,
                                        columns: [[
                                            {field: 'sno', title: '学号', width: 100},
                                            {field: 'sname', title: '姓名', width: 100},
                                            {field: 'cno', title: '课程号', width: 100},
                                            {field: 'cname', title: '课程名', width: 100},
                                            {field: 'teacher', title: '教师', width: 100},
                                            {field: 'semester', title: '学期', width: 100},
                                            {field: 'grades', title: '成绩', width: 100}
                                        ]],
                                        onLoadSuccess: function(data){ // 数据加载成功后的回调函数
                                            console.log("Data loaded successfully.");
                                        }
                                    });

                                else{
                                    $.messager.alert('提示',"没有查询到！", 'warning');
                                }
                                // console.log(result);
                            }
                        })
                    }

                }
            </script>
        </tr>
    </table>
</div>
</body>
</html>
<%--style="width:40%;max-width:400px;padding:30px 60px;"--%>
<%--style="width:100%"--%>